$(function () {
    obj.init();

});

var obj = new function () {
    'use strict';
    return {
        dataGrid:null,
        type: null,
        init:function () {
            this.type    = xhTool.getQuery('type');
            this.dataGrid = new xhDataGrid($('#list'), 'grade/getList',{type:this.type});
            this.dataGrid.parseToolbar().init().activeButton([], ['bt_list_del']);
            this.funObj().bindDataGridEvent();
            this.listener();
        },
        listener:function () {
            var $this = this;

            //新增事件按钮
            $('#bt_list_add').on('click',function () {
                $this.funObj().openAddForm();
            });

            $('#bt_list_del').on('click',function () {
                $this.funObj().askDelQuestion();
            });

            //搜索
            $('#bt_list_search').click(function () {
                $this.funObj().search();
            });
        },
        funObj:function () {
            var $this = this;
            return {
                bindDataGridEvent:function () {
                    $this.dataGrid.onDblClickRow = function (rowIndex, rowData) {
                        window.top.xhTop.showModal({
                            title: '编辑打分',
                            content: '<iframe  src="'+baseUrl+'grade/gradeForm?iRecId='+rowData['iRecId']+'"  style="width: 100%;;border-style: none;padding: 0px;height:300px"  scrolling="yes"   ></iframe>',
                            button:'提交',
                            backClose:false
                        });
                    }
                },
                openAddForm:function () {
                    window.top.xhTop.showModal({
                        title: '新增打分',
                        content: '<iframe  src="'+baseUrl+'grade/gradeForm?type='+$this.type+'"  style="width: 100%;;border-style: none;padding: 0px;height:300px"  scrolling="yes"   ></iframe>',
                        button:'提交',
                        backClose:false
                    });
                },
                askDelQuestion:function () {
                    var id = $this.dataGrid.getSelectValues('iRecId');
                    xhExtra.askChangeStatus('grade/delGrade',{id:id},null,null,function (res) {
                        window.top.xhTop.showSuccess(res.msg);
                        $this.dataGrid.reload();
                    });
                },
                search:function () {
                    $this.dataGrid.reload({type:$this.type,schoolId: xhExtra.getValue($('#list_search_school')) , month: xhExtra.getValue($('#list_search_month')) });
                },
            }
        }
    }
};